<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.qijia.travel.app.*"  %>
<%@ page import="com.qijia.travel.domain.*"  %>
<%@ page import="com.qijia.travel.common.*"  %>
<%
Guide guide = (Guide)session.getAttribute(Constants.USER_KEY);
if(guide.getGuideType()==null||guide.getGuideType()!=1){
out.println("<script>alert('你没有此权限，请联系管理员开通此权限!');window.close();window.parent.location.reload();</script>");
}
int guideType = guide.getGuideType();
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String guideId = request.getParameter("guideId");
GuideManager guideManager = new GuideManager();
guide = new Guide();

boolean modify = false;
if(guideId!=null)modify = true;
GuideAccount account = new GuideAccount();
if(modify){

try{
   int ID = Integer.parseInt(guideId);
   guide = guideManager.getGuideById(ID);
   account = guideManager.getAccountInfo(ID);
   if(guide==null){
      out.println("<script>alert('该导游不存在');window.close();window.parent.location.reload();</script>");
   }
 }catch(NumberFormatException e){
   out.println("<script>alert('该导游不存在');window.close();window.parent.location.reload();</script>");
 }catch(AppErrorException ex){
   out.println("<script>alert('获取数据失败!');window.close();window.parent.location.reload();</script>");
}
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
	margin:0;
	padding:10px 0;
	font-size:12px;
}
ul,li{
    list-style:none;
}
textarea{width:150px;font-size:12px;}
.ipt{width:150px;}
.ipt2{width:40px;}
.btn{border:#002d96 1px solid; padding:4px 4px 2px; font-size:12px; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#FFFFFF, EndColorStr=#9DBCEA); cursor:hand; color:black;}
#wrapper{
	width:460px;
	height:320px;
	margin:0 auto;
	overflow:hidden;
}
#content{
    float:left;
	width:460px;
	height:auto;
	padding:10px 0;
}
#content ul{
	float:left;
	width:100%;
	height:auto;
}
#content li{
	float:left;
	width:100%;
	height:auto;
	line-height:30px;
}
#content span{
    float:left;
	display:block;
	width:100px;
	text-align:right;
}
-->
</style>
</head>

<body>
<div id="wrapper">
    <form method="post" action="">
    <div id="content">
	    <ul>
	       <%
	        if(guideType==1){//特殊账号
	        %>
	        
	        <li><span>用户名：</span><input type="text" name="account.accountName" class="ipt" <%=account==null||account.getAccountName()==null?"":" readonly=readonly "%> value="<%=account==null||account.getAccountName()==null?"":account.getAccountName()%>"/></li>
	        <li><span>登录密码：</span><input type="password" name="account.password" class="ipt" value=""/><input type="button" value="<%=account==null||account.getAccountName()==null?"创建登录账号":"修改登录密码"%>" onclick="createAccount()"/><input type=hidden name="account.guideId" value="<%=guide.getGuideId()%>"/></li>
	        <%
	        }
	         %>
	        
		    <li><span>姓名：</span><input type="text" name="guide.guideName" class="ipt" value="<%=guide.getGuideName()==null?"":guide.getGuideName()%>"/></li>
			<li><span>类型：</span>
			  <select name="guide.guideType">
			   <option <%if(null!=guide.getGuideType() && guide.getGuideType()==1)out.print("selected"); %> value="1">一线</option>
			   <option <%if(null!=guide.getGuideType() && guide.getGuideType()==2)out.print("selected"); %> value="2">二线</option>
			  </select>
			</li>
			<% if( null!=guide.getGuideType() && 2==guide.getGuideType()){%>
			<li><span>所属一线：</span><input type="text" name="guide.belongTo" class="ipt" value="<%=guide.getBelongTo()==null?"":guide.getBelongTo()%>"/></li>
			<% } %>
			<li><span>排序号：</span><input type="text" name="guide.guideSeq"  class="ipt" value="<%=guide.getGuideSeq()==null?"":guide.getGuideSeq()%>" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/></li>
			<li><span>性别：</span>
			  <input type="radio" name="guide.guideSex" value="1" <%if(guide.getGuideSex()==null||"1".equals(guide.getGuideSex()))out.print("checked='checked'"); %>/>男
			  <input type="radio" name="guide.guideSex" value="2" <%if("2".equals(guide.getGuideSex()))out.print("checked='checked'"); %>/>女</li>
			<li><span>手机号：</span><input type="text" name="guide.mobile"  class="ipt" value="<%=guide.getMobile()==null?"":guide.getMobile()%>" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"/></li>
			<li><span>联系电话：</span><input type="text" name="guide.phone" class="ipt" value="<%=guide.getPhone()==null?"":guide.getPhone()%>"/></li>
			<% if(modify){%>
			<li style="padding:0 0 0 100px;"><input name="" type="button" class="btn" value="确定" onclick="updateGuide()"/></li>
		    <%}else{%>
		    <li style="padding:0 0 0 100px;"><input name="" type="button" class="btn" value="确定" onclick="createGuide()"/></li>
		    <%}%>
		    
		</ul>
	</div>
	</form>
</div>
<script src="<%=basePath%>dwr/interface/guideManager.js"></script>
<script src="<%=basePath%>dwr/engine.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<script>
<% if(modify){%>
 function updateGuide(){
   var data=new Object;
   data['guideId']=<%=guideId%>;
   $("input[name^=guide]").each(function(e){
       if(this.type=="radio" && !this.checked)return;
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   $("select[name^=guide]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=$(this).val();
   });
   guideManager.updateGuide(data,function(e){
     alert("修改成功!");
     window.close();
     window.parent.location.reload();
   });
 }
 
 function createAccount(){
   var data=new Object;
   $("input[name^=account]").each(function(e){
       if(this.type=="radio" && !this.checked)return;
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   guideManager.createAccount(data,function(data){
     alert(data);
     window.close();
     window.parent.location.reload();
   });
 
 }
<%}else{%>
 function createGuide(){
   var data=new Object;
   $("input[name^=guide]").each(function(e){
       if(this.type=="radio" && !this.checked)return;
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=this.value;
   });
   $("select[name^=guide]").each(function(e){
       this.name=this.name.substring(this.name.indexOf(".")+1);
       if($.trim(this.value)!="")
       data[this.name]=$(this).val();
   });
   guideManager.createGuide(data,function(e){
     alert("添加成功!");
     window.close();
     window.parent.location.reload();
   });
 }
 <%}%>
</script>
</body>
</html>
